<template>
  <div>
    <template v-for="(item, index) in controlProperties">
      <div :key="index">
        <KFormItem
          ref="nestedComponents"
          @change="handleChange"
          :disabled="disabled"
          :dynamicData="dynamicData"
          :record="item"
          :formConfig="formConfig"
          :inputCtrlVal = "getValue(item.model)"
          :config="config"
        />
      </div>
    </template>
  </div>
</template>
<script>
import RenderPropertyItem from "@/visualization/ControlProperties/child.vue";
import KFormItem from "../KFormItem/index";
export default {
  name: "controlproperties",
  props: ["controlProperties"],
  components: {
    RenderPropertyItem,
    KFormItem
  },
  data() {
    return {
      items: [],
      data:{},
      value:true,
      dynamicData:[],
      id:0,
      formConfig:[],
      config:[]
    };
  },
  methods:{
    getValue(field){
      // if(document.getElementById(field)) {
      //   document.getElementById(field).checked = this.data[field];
      // }
      // debugger;
      return this.data[field];
      // if(this.data[field]) {
      //   return this.data[field];
      // }else {
      //   return "";
      // }
    },
    handleInput(field,value){

      //console.log("curvalue:"+document.getElementById(field).value);
      // console.log('value:'+value);
      // console.log('value.data:'+value.data);
      this.data[field] = document.getElementById(field).value;
      // console.log('this.data:'+this.data);
      console.log('data[field]:'+ this.data[field]);
    },
    onSwitch(field,value){
      debugger;
      // if(value) {
      //   this.data[field] = "true";
      // }else{
      //   this.data[field] = "false";
      // }
      this.data[field]=document.getElementById(field).checked;
      // console.log('this.data:'+this.data);
      console.log('data[field]:'+ this.data[field]);
    },
    getPropertiesValue(){
      var jsonStr = JSON.stringify(this.data);
      console.log('retun json str:'+jsonStr);
      var retJson = JSON.parse(jsonStr);
      return retJson;
    },
    setPropertiesValue(propertiesData){
      //debugger;
      if(propertiesData==null){
       this.data = {};
      }else{
      this.data = propertiesData;
      }
      console.log('set json str:'+JSON.stringify(this.data));
    },
    handleChange(value, key) {
       debugger;
      this.data[key] = value;
    }
  },
  mounted(){
    this.data = {};
  }
};
</script>

<style scoped></style>
